package com.yupi.springbootinit.manager;

import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author vvv
 * @date 2023-11-29 21 35
 * discription
 */
@Service
public class AiManager {

    @Resource
    private YuCongMingClient yuCongMingClient;

    public String doChat(String message, Long modelId) {

        if (StringUtils.isEmpty(message) || modelId == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        DevChatRequest devChatRequest = new DevChatRequest();
        devChatRequest.setMessage(message);
        devChatRequest.setModelId(modelId);

        BaseResponse<DevChatResponse> result = yuCongMingClient.doChat(devChatRequest);
        if (StringUtils.isEmpty(message) || modelId == null) {
            throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
        }
        String content = result.getData().getContent();
        return content;
    }
}
